///material路由跳转，安卓底部弹出，ios滑入
// import 'package:flutter/material.dart';
///统一路由跳转风格 cupertino (android ios都使用滑入效果)
import 'package:flutter/cupertino.dart';
import 'package:flutter_base_study/pageview/pageview_page.dart';
import 'package:flutter_base_study/pageview/pageviewautoswiper_page03.dart';
import 'package:flutter_base_study/pageview/pageviewbuild_page.dart';
import 'package:flutter_base_study/pageview/pageviewfull_page.dart';
import 'package:flutter_base_study/pageview/pageviewkeepalive_page04_base.dart';
import 'package:flutter_base_study/pageview/pageviewswiper_page.dart';
import 'package:flutter_base_study/pageview/pageviewswiper_page02.dart';

import '../pageview/pageviewkeepalive_page04.dart';
import '../routers/form_page.dart';
import '../routers/news_page.dart';
import '../routers/search_page.dart';
import '../routers/shoppage.dart';
import '../scaffold/page/home.dart';
import '../scaffold/tabbar_tabbarview_demo.dart';
import '../scaffold/tabs.dart';

///命名路由封装
///命名路由传参跳转

///--2、调用onGenerateRoute处理 固定写法，这个方法也相当于一个中间件，这里可以做权限判断

///--1、定义Map类型的routes
Map routes = {
  //命名路由传值
  '/form_page': (context, {arguments}) => FormPage(arguments: arguments),
  "/shop": (context, {arguments}) => ShopPage(arguments: arguments),
  '/home': (context) => const Home(),
  '/news_page': (context) => const NewsPage(),
  '/search_page': (context) {
    return SearchPage();
  },
  '/tabbar_tabbarview_demo': (context) => const TabBarViewDemo(),
  '/': (context) => const Tabs(),

  'pageview_page': (context) => const PageviewPage(),
  'pageviewbuild_page': (context) => const PageViewbuildPage(),
  'pageviewfull_page': (context) => const PageviewFullPage(),
  'pageviewswiper_page': (context) => const PageviewSwiper(),
  'pageviewswiper_page02': (context) => const PageviewSwiperPage02(),
  'pageviewautoswiper_page03': (context) => const PageViewSwiperAutoDemo(),
  'pageviewkeepalive_page04_base': (context) =>
      const PageviewKeepAliveBasePage(),
  'pageviewkeepalive_page04': (context) => const PageviewKeepAlivePage(),
};
var onGenerateRoute = (RouteSettings settings) {
  //命名路由名城
  final String? name = settings.name;
  final Function? pageContentBuilder = routes[name];
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      ///默认安卓弹出效果
      // final Route route = MaterialPageRoute(
      //     builder: (context) =>
      //         pageContentBuilder(context, arguments: settings.arguments));
      ///滑入效果
      final Route route = CupertinoPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
      // 26.5.2、定义页面接收
      // arguments传参
      // 26.5.3、跳转页面实现传参
    } else {
      ///弹出效果
      // final Route route =
      //     MaterialPageRoute(builder: (context) =
      ///滑入效果
      final Route route =
          CupertinoPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
  return null;
};
/**普通路由，命名路由
 *
 * flutter中替换路由:    1跳2跳3，2中使用替换路由跳转到3点击3的返回到1
 * Navigator.of(context).pushReplacementNamed('/registerSecond');
 *
 * flutter返回根路由： 1跳2跳3，3中使用返回根路由直接返回到Tabs页
 * Navigator.of(context).pushAndRemoveUntil(
 *      MaterialPageRoute(build:(BuildContext context){
 *        return const Tabs();
 * }),(route) => false);
 *
 *
 */
